# This file is part of OrangeSpider. OrangeSpider is a meta model based
# development tool.
# 
# OrangeSpider is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# OrangeSpider is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with OrangeSpider.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2009 Stefan Nikolaus <OrangeSpiderMaster@googlemail.com>

from MetaModel import *
import Types

class Builder:
    def __init__(self, name, typ, watcher = None):
        r = None
        if typ == "SpiderTST":
            r = MetaModel(name, "SpiderTST", watcher)
            r.MetaEnum("ColorEnum", "Blue", "A color enumeration")
            r.MetaAtom("ColorEnum", "Blue")
            r.MetaAtom("ColorEnum", "Grey")
            r.MetaAtom("ColorEnum", "Green")
            r.MetaClass("Graph", "A graph")
            r.MetaClass("State", "A class for storing states")
            r.MetaClass("Action", "An action for a state")
            r.MetaAssoc("State.Has.Action", "A state has several actions", 
                        ONE_TO_MANY, True)
            r.MetaAssoc("Graph.Contains.State", "A graph contains states", 
                        ONE_TO_MANY, True)
            r.MetaProperty("Graph", "Name", "String", 
                        "The name of the graph")
            r.MetaProperty("State", "Name", "String", 
                        "The name of the state")
            r.MetaProperty("State", "Order", "Integer", 
                        "The order of the state")
            r.MetaProperty("State", "ColorEnum", "ColorEnum", 
                        "The color of the state")
            r.MetaProperty("Action", "Name", "String", "The statename")
            r.MetaClass("Test", "A test class")
            r.MetaProperty("Test", "Name", "String", "The statename")
            r.MetaProperty("Test", "String", "String", "String variable")
            r.MetaProperty("Test", "Integer", "Integer", "Integer variable")
            r.MetaProperty("Test", "Boolean", "Boolean", "Boolean variable")
            r.MetaProperty("Test", "Float", "Float", "Float variable")
            r.MetaProperty("Test", "Picture", "Picture", "Picture variable")
            r.MetaProperty("Test", "Text", "Text", "Text variable")
            r.MetaProperty("Test", "DateTime", "DateTime", "DateTime variable")
            r.MetaProperty("Test", "ColorEnum", "ColorEnum", "ColorEnum variable")
            r.MetaProperty("Test", "TimeStamp", "TimeStamp", "TimeStamp variable")
            r.MetaProperty("Test", "Color", "Color", "Color variable")
            r.MetaProperty("Test", "Font", "Font", "Font variable")
            r.MetaProperty("Test", "Blob", "Blob", "Blob variable")
            r.MetaProperty("Test", "FileString", "FileString", "FileString variable")
            r.MetaProperty("Test", "Directory", "Directory", "Directory variable")
            r.MetaProperty("Test", "Size", "Size", "Size variable")
            r.MetaProperty("Test", "Point", "Point", "Point variable")
            r.MetaProperty("Test", "Rect", "Rect", "Rect variable")
            r.MetaProperty("Test", "Flags", "Flags", "Flags variable")
            r.MetaProperty("Test", "Url", "Url", "Url variable")

            r.MetaClass("Category", "A test category")
            r.MetaProperty("Category", "Name", "String", "Category name")
            r.MetaAssoc("Category.Contains.Test", "", ONE_TO_MANY, True)

            
        elif typ == "SpiderDIAGRAM":
            r = MetaModel(name, "SpiderDIAGRAM", watcher)
            r.MetaEnum("ToolType", "Node", "The type of the tool direction")
            r.MetaAtom("ToolType", "Node")
            r.MetaAtom("ToolType", "Edge")
            r.MetaAtom("ToolType", "NodeEdge")
            r.MetaAtom("ToolType", "DrawNode")

            r.MetaEnum("ShapeType", "Container", "A shape type")
            r.MetaAtom("ShapeType", "Picture")
            r.MetaAtom("ShapeType", "Container")
            r.MetaAtom("ShapeType", "Text")
            r.MetaAtom("ShapeType", "Diagram")

            r.MetaEnum("PenStyle", "SolidLine", "A solid line")
            r.MetaAtom("PenStyle", "NoPen")
            r.MetaAtom("PenStyle", "SolidLine")
            r.MetaAtom("PenStyle", "DashLine")
            r.MetaAtom("PenStyle", "DotLine")
            r.MetaAtom("PenStyle", "DashDotLine")
            r.MetaAtom("PenStyle", "DashDotDotLine")

            r.MetaClass("Diagram", "A diagram definition")
            r.MetaProperty("Diagram", "Name", "String", "The name")
            r.MetaProperty("Diagram", "Root", "String", "If set a instance of this meta class must exist")

            r.MetaClass("NodeDef", "A definition for a graphical node")
            r.MetaProperty("NodeDef", "Name", "String", "The name")
            r.MetaProperty("NodeDef", "MetaEntity", "String", 
                           "The name of the meta entity, which instances should be displayed as node")

            r.MetaClass("EdgeDef", "A definition for a graphical edge")
            r.MetaProperty("EdgeDef", "Name", "String", "The name")
            r.MetaProperty("EdgeDef", "MetaEntity", "String", 
                           "The name of the meta entity, which instances should be displayed as link")
            r.MetaProperty("EdgeDef", "StartAssoc", "String", 
                           "If meta entity is a class, this is the link to the source class")
            r.MetaProperty("EdgeDef", "EndAssoc", "String", 
                           "If meta entity is a class, this is the link to the target class")

            r.MetaClass("Tool", "A tool can create objects on a diagram pane")
            r.MetaProperty("Tool", "Name", "String", "The name")
            r.MetaProperty("Tool", "Icon", "Picture", "The tool icon")
            r.MetaProperty("Tool", "Type", "ToolType", "The type of the tool")
            r.MetaProperty("Tool", "MetaEntity", "String", 
                           "The name of the meta entity which should be created")
            r.MetaProperty("Tool", "Source", "String", 
                           "If type is a NodeEdge, this is the MetaAssoc source link")
            r.MetaProperty("Tool", "Target", "String", 
                           "If type is a NodeEdge, this is the MetaAssoc target link")            

            r.MetaClass("Shape", "A shape")
            r.MetaProperty("Shape", "Name", "String", "An informal name")
            r.MetaProperty("Shape", "Type", "ShapeType", "The type")
            r.MetaProperty("Shape", "DefaultSize", "Size", "The default size of the item")
            r.MetaProperty("Shape", "Path", "String", "Only for containers: A navigable metamodel path")
            
            r.MetaProperty("Shape", "BackgroundColor", "Color", "The color")
            r.MetaProperty("Shape", "ForegroundColor", "Color", "The color")
            r.MetaProperty("Shape", "BorderColor", "Color", "The color")
            r.MetaProperty("Shape", "PenStyle", "PenStyle", "A style of the pen")
            r.MetaProperty("Shape", "PenWidth", "Integer", "The width of the pen")
            
            r.MetaProperty("Shape", "Picture", "Picture", "The picture")
            r.MetaProperty("Shape", "Offset", "Point", "The offset")
            
            r.MetaProperty("Shape", "Text", "String", "A text")
            r.MetaProperty("Shape", "Font", "Font", "A font")
            r.MetaProperty("Shape", "FontSize", "Integer", "A font size")
            
            r.MetaProperty("Shape", "Margin", "Integer", "A margin")
            r.MetaProperty("Shape", "Layout", "String", "Vertical or horizontal")
            r.MetaProperty("Shape", "Alignment", "String", "Top, Left, Right, Bottom, TopLeft, Fill?")
            r.MetaProperty("Shape", "IsVisible", "Boolean", "True if it is visible")

            r.MetaClass("Line", "A line visualizes an edge")
            r.MetaProperty("Line", "ForegroundColor", "Color", "The color")
            r.MetaProperty("Line", "PenStyle", "PenStyle", "A style of the pen")
            r.MetaProperty("Line", "PenWidth", "Integer", "The width of the pen")

            r.MetaAssoc("NodeDef.VisualizedBy.Shape", "", ONE_TO_ONE, True)
            r.MetaAssoc("Shape.Contains.Shape", "", ONE_TO_MANY, True)

            r.MetaAssoc("EdgeDef.VisualizedBy.Line", "", ONE_TO_ONE, True)
            r.MetaAssoc("Line.Start.Shape", "", MANY_TO_ONE, False)
            r.MetaAssoc("Line.End.Shape", "", MANY_TO_ONE, False)

            r.MetaClass("Mapping")
            r.MetaProperty("Mapping", "Property", "String", "Property of the shape to influence")
            r.MetaProperty("Mapping", "Expression", "Text", "A python expression with a data object")
            r.MetaAssoc("Shape.FilledBy.Mapping", "", ONE_TO_MANY, True)
            r.MetaAssoc("Line.FilledBy.Mapping", "", ONE_TO_MANY, True)

            r.MetaClass("Picture")
            r.MetaProperty("Picture", "Name", "String", "A name for a picture")
            r.MetaProperty("Picture", "Picture", "Picture", "A picture")

        elif typ == "SpiderCOMP":
            r = MetaModel(name, "SpiderCOMP", watcher)
            r.MetaEnum("ConnectorDirection", "Input", "A connector direction")
            r.MetaAtom("ConnectorDirection", "Input")
            r.MetaAtom("ConnectorDirection", "Output")
            r.MetaAtom("ConnectorDirection", "InOut")
            r.MetaClass("Component", "A component")
            r.MetaProperty("Component", "Name", "String", "The name")
            r.MetaProperty("Component", "UUID", "String", "The uuid of the component")
            r.MetaClass("Connector", 
                        "A connector is used for describing input and output of the component")
            r.MetaProperty("Connector", "Direction", "ConnectorDirection")
            r.MetaProperty("Connector", "Name", "String")
            r.MetaProperty("Connector", "Type", "String")
            r.MetaAssoc("Component.Has.Connector", "", ONE_TO_MANY, True)

            r.MetaClass("Interface", "An interface")
            r.MetaProperty("Interface", "Name", "String", "An interface name")

            r.MetaClass("ComponentType", "A component type")           
            r.MetaProperty("ComponentType", "Description", "String", "The description")
            r.MetaProperty("ComponentType", "Name", "String", "The name")
            r.MetaProperty("ComponentType", "HasUi", "Boolean", 
                           "True, if component can be edited visible")
            r.MetaAssoc("ComponentType.Supports.Interface", "", ONE_TO_MANY, False)
            r.MetaAssoc("ComponentType.Instance.Component", "", ONE_TO_MANY, True)

        elif typ == "SpiderSQL":
             r = MetaModel(name, "SpiderSQL", watcher)
             r.MetaEnum("Action", "NoAction", "An action to perform on changes")
             r.MetaAtom("Action", "NoAction")
             r.MetaAtom("Action", "Cascade")

             r.MetaClass("Table", "A table")
             r.MetaProperty("Table", "Name", "String", "A table has a name")
             r.MetaClass("Field", "A field")
             r.MetaProperty("Field", "Name", "String", "A field has a name")
             r.MetaProperty("Field", "Size", "Integer", "A field has a size")
             r.MetaProperty("Field", "IsNull", "Boolean", "A field may have null values")
             r.MetaProperty("Field", "Default", "String", "The default value of the field")
             r.MetaProperty("Field", "Comment", "String", "Comment for the field")
             r.MetaProperty("Field", "ForeignName", "String", "Foreign name")
             r.MetaClass("PrimaryKey", "A primary key")
             r.MetaProperty("PrimaryKey", "Name", "String", "A primary key has a name")
             r.MetaClass("Index", "An index")
             r.MetaProperty("Index", "Name", "String", "An index has a name")

             r.MetaClass("ForeignKey", "A foreign key")
             r.MetaProperty("ForeignKey", "Name", "String", "A foreign key has a name")
             r.MetaProperty("ForeignKey", "DeleteAction", "Action", "The action to perform when a entry is deleted.")
             r.MetaProperty("ForeignKey", "UpdateAction", "Action", "The action to perform when a entry is updated.")
             
             r.MetaClass("Schema", "A database scheme")
             r.MetaProperty("Schema", "Name", "String", "A schema has a name")
             r.MetaClass("DataType", "A data type")
             r.MetaProperty("DataType", "Name", "String", "A data type has a name")
             r.MetaAssoc("Schema.Contains.Table", "", ONE_TO_MANY, True)
             r.MetaAssoc("Table.Contains.Field", "", ONE_TO_MANY, True)
             r.MetaAssoc("Table.Has.Index", "", ONE_TO_MANY, True)
             r.MetaAssoc("Table.Has.PrimaryKey", "", ONE_TO_OPT, True)
             r.MetaAssoc("PrimaryKey.Contains.Field", "", ONE_TO_MANY, False)
             r.MetaAssoc("Index.Contains.Field", "", ONE_TO_MANY, False)
             r.MetaAssoc("Field.Has.DataType", "", MANY_TO_ONE, False)
             r.MetaAssoc("Table.Has.ForeignKey", "", ONE_TO_MANY, True)
             r.MetaAssoc("ForeignKey.RefersTo.Table", "", MANY_TO_ONE, False)
             r.MetaAssoc("ForeignKey.Contains.Field", "", MANY_TO_ONE, True)

        elif typ == "SpiderINI":
             r = MetaModel(name, "SpiderINI", watcher)
             r.MetaClass("IniFile", "An ini file")
             r.MetaProperty("IniFile", "Name", "String", "The filename")
             r.MetaClass("Section", "A section in an ini file")
             r.MetaProperty("Section", "Name", "String", "The section name")
             r.MetaClass("Setting", "A setting in a section")
             r.MetaProperty("Setting", "Name", "String", "The setting name")
             r.MetaProperty("Setting", "Value", "String", "The setting value")
             r.MetaAssoc("IniFile.Contains.Section", "", ONE_TO_MANY, True)
             r.MetaAssoc("Section.Has.Setting", "", ONE_TO_MANY, True)

        elif typ == "SpiderFILE":
             r = MetaModel(name, "SpiderFILE", watcher)
             r.MetaClass("Folder", "An folder in the file system")
             r.MetaProperty("Folder", "Name", "String", 
                            "The folder name (may be absolute)")
             r.MetaClass("File", "A file in the file system")
             r.MetaProperty("File", "Name", "String", "The file name")
             r.MetaAssoc("Folder.Contains.Folder", "", OPT_TO_MANY, True)
             r.MetaAssoc("Folder.Contains.File", "", ONE_TO_MANY, True)

        elif typ == "SpiderPROJECT":
             r = MetaModel(name, "SpiderPROJECT", watcher)
             r.MetaEnum("FolderType", "Folder", "A folder type")
             r.MetaAtom("FolderType", "Folder")
             r.MetaAtom("FolderType", "Project")
             r.MetaAtom("FolderType", "Configuration")

             r.MetaClass("Folder", "An folder in project")
             r.MetaProperty("Folder", "Name", "String", 
                            "The folder name (may be absolute)")
             r.MetaProperty("Folder", "Type", "FolderType", 
                            "The folder type")

             r.MetaClass("File", "A file in the file system")
             r.MetaProperty("File", "Name", "String", "The file name")

             r.MetaClass("Script", "A script")
             r.MetaProperty("Script", "Name", "String", "The file name")

             r.MetaClass("Model", "A stored metamodel")
             r.MetaProperty("Model", "Name", "String", "The file name")
             r.MetaProperty("Model", "Type", "String", "The type of the metamodel")
             r.MetaProperty("Model", "UUID", "String", "The uuid of the metamodel")

             r.MetaClass("Package", "A package is a distributable project")
             r.MetaProperty("Package", "Name", "String", "The package name")
             r.MetaProperty("Package", "Icon", "Picture", "")
             r.MetaProperty("Package", "Description", "String", "")
             r.MetaProperty("Package", "Author", "String", "")
             r.MetaProperty("Package", "MajorVersion", "Integer", "")
             r.MetaProperty("Package", "MinorVersion", "Integer", "")
             r.MetaProperty("Package", "Date", "DateTime", "")
             r.MetaProperty("Package", "UpdateUrl", "Url", "")

             r.MetaClass("Setting", "A setting for the package configuration")
             r.MetaProperty("Setting", "Name", "String", "Setting Name")
             r.MetaProperty("Setting", "Value", "String", "Value")
             r.MetaAssoc("Package.Has.Setting", "", ONE_TO_MANY, True)

             r.MetaAssoc("Package.Requires.Package", "", MANY_TO_MANY, False)
             r.MetaAssoc("Folder.Contains.Folder", "", OPT_TO_MANY, True)
             r.MetaAssoc("Folder.Contains.File", "", ONE_TO_MANY, True)
             r.MetaAssoc("Folder.Contains.Model", "", ONE_TO_MANY, True)
             r.MetaAssoc("Folder.Contains.Script", "", ONE_TO_MANY, True)
             r.MetaAssoc("Package.Has.Folder", "", ONE_TO_ONE, True)
             
        elif typ == "SpiderMMM":
             r = MetaModel(name, "SpiderMMM", watcher)
             r.MetaEnum("Cardinality", "MANY", "The cardinality of an association")
             r.MetaAtom("Cardinality", "OPTIONAL", "0..1")
             r.MetaAtom("Cardinality", "ONE", "1")
             r.MetaAtom("Cardinality", "MANY", "N")
     
             r.MetaClass("MetaClass", "A meta class")
             r.MetaProperty("MetaClass", "Name", "String", "The name")
             r.MetaProperty("MetaClass", "Description", "String", 
                            "The description")
             r.MetaProperty("MetaClass", "Icon", "Picture", 
                            "The picture")
     
             r.MetaClass("MetaAssoc", "A meta association")
             r.MetaProperty("MetaAssoc", "Name", "String", "The name")
             r.MetaProperty("MetaAssoc", "Description", "String", 
                            "The description")
             r.MetaProperty("MetaAssoc", "SourceName", "String", 
                            "The source name")
             r.MetaProperty("MetaAssoc", "TargetName", "String", 
                            "The target name")
             r.MetaProperty("MetaAssoc", "AssocName", "String", 
                            "The association name")
             r.MetaProperty("MetaAssoc", "SourceCardinality", "Cardinality", 
                            "The target cardinality")
             r.MetaProperty("MetaAssoc", "TargetCardinality", "Cardinality", 
                            "The target cardinality")
             r.MetaProperty("MetaAssoc", "Aggregation", "Boolean", 
                            "Shared or composite association")
             r.MetaProperty("MetaAssoc", "Icon", "Picture", 
                            "Picture")
     
             r.MetaClass("MetaType", "A meta type")
             r.MetaProperty("MetaType", "Name", "String", "The name")
             r.MetaProperty("MetaType", "Description", "String", 
                            "The Description")
             r.MetaProperty("MetaType", "DefaultValue", "String", 
                            "The default value for a property")
     
             r.MetaClass("MetaEnum", "A meta enumeration")
             r.MetaProperty("MetaEnum", "Name", "String", "The name")
             r.MetaProperty("MetaEnum", "Description", "String", 
                            "The Description")
     
             r.MetaClass("MetaAtom", "A meta atom")
             r.MetaProperty("MetaAtom", "Name", "String", "The name")
             r.MetaProperty("MetaAtom", "Description", "String", 
                            "The Description")
     
             r.MetaClass("MetaProperty", "A meta property")
             r.MetaProperty("MetaProperty", "Name", "String", "The name")
             r.MetaProperty("MetaProperty", "Description", "String", 
                            "The Description")
             r.MetaProperty("MetaProperty", "IsUnique", "Boolean", 
                            "True, if this meta property is a unique identifier within the aggregation context.")
             r.MetaProperty("MetaProperty", "IsIdentifying", "Boolean", 
                            "True, if this property is the identifying property for the user.")
     
             r.MetaClass("MetaModel", "The meta model")
             r.MetaProperty("MetaModel", "Name", "String", "The name")
             r.MetaProperty("MetaModel", "Description", "String", 
                            "The Description")
             r.MetaProperty("MetaModel", "Type", "String", "The type of the meta model")
             r.MetaProperty("MetaModel", "FileName", "FileString", "The filename")
             r.MetaProperty("MetaModel", "UUID", "String", "The unique identifier")
             r.MetaProperty("MetaModel", "Icon", "Picture", "A picture for this metamodel")
             r.MetaProperty("MetaModel", "MajorVersion", "Integer", "The major version")
             r.MetaProperty("MetaModel", "MinorVersion", "Integer", "The minor version")
          
             r.MetaAssoc("MetaAssoc.Source.MetaClass", "", MANY_TO_ONE, False)
             r.MetaAssoc("MetaAssoc.Target.MetaClass", "", MANY_TO_ONE, False)
             r.MetaAssoc("MetaClass.Has.MetaProperty", "", ONE_TO_MANY, True)
             r.MetaAssoc("MetaAssoc.Has.MetaProperty", "", ONE_TO_MANY, True)
             r.MetaAssoc("MetaProperty.Has.MetaType", "", MANY_TO_ONE, False)
             r.MetaAssoc("MetaType.Is.MetaEnum", "", ONE_TO_OPT, True)
             r.MetaAssoc("MetaEnum.HasPart.MetaAtom", "", ONE_TO_MANY, True)
             r.MetaAssoc("MetaModel.Contains.MetaAssoc", "", ONE_TO_MANY, True)
             r.MetaAssoc("MetaModel.Contains.MetaClass", "", ONE_TO_MANY, True)
             r.MetaAssoc("MetaModel.Contains.MetaType", "", ONE_TO_MANY, True)

             # Special: ConstraintManager for MMM metamodels
             assert(r.watcher)
             r.watcher.addListener(ConstraintManagerMMM(), "ConstraintManagerMMM")
        else:
            assert(0)        
        self.repository = r

# We watch about renaming object in the MMM metamodel
class ConstraintManagerMMM:
    def __init__(self):
        pass
    def propertyChanged(self, object, key, oldValue, newValue):
        if object.isClass():
            if object.intention["Name"] == "MetaClass":
                if key != "Name":
                    return
                for metaassoc in object.eachIncomingClass("MetaAssoc.Source.MetaClass"):
                    self._updateMetaAssoc(metaassoc)
                for metaassoc in object.eachIncomingClass("MetaAssoc.Target.MetaClass"):
                    self._updateMetaAssoc(metaassoc)
            if object.intention["Name"] == "MetaAssoc":
                if key == "Name":
                   pass
                elif key == "SourceName":
                   pass
                elif key == "TargetName":
                   pass
                elif key == "AssocName":
                   self._updateMetaAssoc(object)

    def entityCreated(self, object):
        if object.isAssoc():
            if object.intention["Name"] == "MetaAssoc.Source.MetaClass":
                self._updateMetaAssoc(object.source)
            if object.intention["Name"] == "MetaAssoc.Target.MetaClass":
                self._updateMetaAssoc(object.source)
        if object.isClass():
            if object.intention["Name"] == "MetaAssoc":
                if object["AssocName"] == "":
                    object["AssocName"] = "Assoc"

            if object.intention["Name"] == "MetaProperty":
                if object["Name"] != "Id":
                    r = object.metaModel()
                    metaType = r.find("MetaType", "Name", "String")
                    assert(metaType)
                    r.Assoc(object, metaType, "Has")

            if object.intention["Name"] == "MetaModel":
                r = object.metaModel()
                self._createMetaType(object, "String", "")
                self._createMetaType(object, "Integer", "0")
                self._createMetaType(object, "Boolean", "0")
                self._createMetaType(object, "Float", "0.0")
                self._createMetaType(object, "Picture", "")
                self._createMetaType(object, "Text", "")
                self._createMetaType(object, "DateTime", "(2000, 1, 1, 0, 0, 0)")
                self._createMetaType(object, "TimeStamp", "(2000, 1, 1, 0, 0, 0)")
                self._createMetaType(object, "Color", "(0, 0, 0, 0)")
                self._createMetaType(object, "Font", "")
                self._createMetaType(object, "Blob", "")
                self._createMetaType(object, "FileString", "")
                self._createMetaType(object, "Directory", "")
                self._createMetaType(object, "Size", "(0.0, 0.0)")
                self._createMetaType(object, "Point", "(0.0, 0.0)")
                self._createMetaType(object, "Rect", "(0.0, 0.0, 0.0, 0.0)")
                self._createMetaType(object, "Flags", "0")
                self._createMetaType(object, "Url", "")

    def entityDeleted(self, object):
        pass

    def _createMetaType(self, object, name, defaultValue):
        r = object.metaModel()
        metatype = r.Class("MetaType")
        metatype["Name"] = name
        metatype["DefaultValue"] = defaultValue
        r.Assoc(object, metatype, "Contains")

    def _updateMetaAssoc(self, metaassoc):
        source = metaassoc.firstOutgoingClass("MetaAssoc.Source.MetaClass")
        if source:
            metaassoc["SourceName"] = source["Name"]
        target = metaassoc.firstOutgoingClass("MetaAssoc.Target.MetaClass")
        if target:
            metaassoc["TargetName"] = target["Name"]
        newName = metaassoc["SourceName"] + "." 
        newName += metaassoc["AssocName"] + "."
        newName += metaassoc["TargetName"]
        metaassoc["Name"] = newName

#MC name change -> alle MetaAssocs pruefen
#MetaAssoc.Source.MetaClass New: MA.change
#MetaAssoc.Target.MetaClass New: MA.change
